package com.atguigu.product.controller;

import com.atguigu.product.bean.Product;
import com.atguigu.product.service.impl.ProductServiceImpl;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author fhs
 * Create by 2025/6/23 09:19
 */
//@RequestMapping("/api/product")//不加基本路径了，只用路径重写
@RestController
public class ProductController {

    @Autowired
    private ProductServiceImpl productServiceImpl;



    //查询商品
    @GetMapping("/product/{id}")
    public Product getProduct(@PathVariable("id") Long productId,
                              HttpServletRequest request) throws InterruptedException {
        String token = request.getHeader("X-token");
        System.out.println("hello,X-token={"+token+"}");
//        int i = 1/0;//自定义的一个异常
        Product product = productServiceImpl.getProductById(productId);

        return product;
    }
}
